package com.lindroy.androidplayer.viewmodels

import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ViewModel
import androidx.lifecycle.map
import androidx.lifecycle.viewModelScope
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.lindroy.androidplayer.logic.model.CollectedWebsiteResp
import com.lindroy.androidplayer.logic.network.base.http.observeResponse
import com.lindroy.androidplayer.logic.network.base.http.observeState
import com.lindroy.androidplayer.logic.network.repository.Repository
import com.lindroy.androidplayer.utils.SingleLiveEvent
import com.lindroy.androidplayer.utils.mapSingle
import com.lindroy.androidplayer.utils.switchMapSingle
import io.reactivex.internal.operators.single.SingleInternalHelper
import kotlinx.coroutines.launch

/**
 * @author Lin
 * @date 2022/2/20
 * @function
 */
class CollectedWebsitesViewModel : ViewModel() {

    private val itemClickAction = SingleLiveEvent<CollectedWebsiteItemViewModel>()

    val collectedWebsite = Repository.getCollectedWebsitesResp()

    val itemClickLiveData = itemClickAction.mapSingle { it }

    fun transData(list: List<CollectedWebsiteResp>) = list.map { item ->
        CollectedWebsiteItemViewModel(
            id = item.id,
            desc = item.desc,
            link = item.link,
            name = item.name,
            itemClickListener = itemClickAction
        )
    }

}